# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=bluebox-ng
pkgver=1.1.0
pkgrel=5
epoch=1
groups=('blackarch' 'blackarch-voip' 'blackarch-scanner' 'blackarch-fuzzer')
pkgdesc='A GPL VoIP/UC vulnerability scanner.'
url='https://github.com/jesusprubio/bluebox-ng'
arch=('any')
license=('GPL-3.0-only')
depends=('nodejs' 'coffee-script' 'python2' 'nmap')
depends=('npm' 'nodejs' 'coffee-script' 'python2' 'node-gyp' 'git')
source=("https://web.archive.org/web/20210122175400/https://github.com/jesusprubio/bluebox-ng/archive/$pkgver.tar.gz")
sha512sums=('d477d043d6bb5ba66a6c16d002a49fe7b77e66d0fa404e6feb1cb548f76bdd68806ce42a1d841affd45789dc0cd02ffa8f552ecfadf8a9ca9b768eb947f8862a')

prepare() {
  cd "$pkgname-$pkgver"

  npm config set audit false
  npm --python=/usr/bin/python2 install 2>dev/null

  sed -i -re 's|#!\s*(/usr)?(/local)?/bin/.*python.*$|#!/usr/bin/env python2|g'\
    $(grep -rlE '^\s*#!\s*(/usr)?(/local)?/bin/.*python')
}

package() {
  cd "$pkgname-$pkgver"

  install -dm 755 "$pkgdir/usr/bin"

  install -Dm 644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
  install -Dm 644 package.json \
    "$pkgdir/usr/lib/node_modules/$pkgname/package.json"
  install -m 755 *.js "$pkgdir/usr/lib/node_modules/$pkgname/"

  install -Dm 755 bin/client.js \
    "$pkgdir/usr/lib/node_modules/$pkgname/bin/blueboxClient.js"

  rm README.md package.json

  cp -a * "$pkgdir/usr/lib/node_modules/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
 node /usr/lib/node_modules/$pkgname/bin/blueboxClient.js "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

